/**
 * jQuery Blink plugin
 * Created by Igor Ramadas for http://counting.to
 */
(function($)
{
    $.fn.blink = function(c)
    {
        // Get the options. Default is 300ms delay, repeating 3 times.
        var options = $.extend({
            delay: 400,
            repeat: 3,
            callback: null
        }, c);

        return this.each(function()
        {
            // Cache the current element.
            var el = $(this);
            el.css("opacity", 0);

            // Timer to blink the element.
            var timer = function(count)
            {
                el.animate({opacity: 0}, options.delay / 4, function()
                {
                    el.animate({opacity: 1}, options.delay / 2);
                });

                if (count > 1)
                {
                    setTimeout(function() { timer(count - 1) }, options.delay);
                }
                else if (options.callback)
                {
                    options.callback(el);
                }
            };

            timer(options.repeat);
        });
    }
}(jQuery));